<template>
	<view class="content">
		<view v-for="item in records" class="cu-timeline">
			<view class="cu-time">{{item.date}}</view>
			<view class="cu-item">
				<view class="content">
					<view class="padding-bottom-sm">
						{{item.personname==null?$t('stranger'):item.personname}}
					</view>
					<view class="cu-capsule radius">
						<view class="cu-tag bg-cyan">{{item.AM}}</view>
						<view class="cu-tag line-cyan">{{item.time}}</view>
					</view>
					<view v-if="item.temperature>0" class="cu-capsule radius">
						<view :class="item.temperature>=37.3?'bg-red':'bg-green'" class="cu-tag">{{$t('temperature')}}</view>
						<view :class="item.temperature>=37.3?'line-red':'line-green'" class="cu-tag">{{item.temperature}}°</view>
					</view>
					<view class="margin-top">
						<image @tap="ViewImage(item.url)" :src="item.url" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		formateDate
	} from "@/common/utils.js"
	export default {
		data() {
			return {
				records: [],
			}
		},
		onLoad(options) {
			//获取用户授权
			let id = options.id; //提取code参数, 用于获取openid
			let type = options.type
			// console.log("id = " + id)
			// id ="2c9029b870cd65810170cd6977a300ad"
			// type = 1
			// console.log("type = " + type)
			if (typeof(id) != 'undefined' && typeof(type) != 'undefined') {
				this.getDetail(id, type)
			}
		},
		methods: {
			ViewImage(url) {
				let urls = [url]
				uni.previewImage({
					urls: urls,
					current: 0
				});
			},
			getDetail(id, type) {
				uni.request({
					url: 'https://kq.lsyat.com/attrecordController.do?QueryCapsin',
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						id: id,
						type: type
					},
					success: (res) => {
						let that = this
						console.log(res)
						if (res.data.code == 0) {
							let list = res.data.data
							let records = []
							list.forEach(function(item) {
								let time = formateDate(new Date(item.capturetime.time), 'Y-M-D h:min A')
								console.log(time)
								records.push({
									name: item.personname,
									year: time.substring(0, 4),
									date: time.substring(0, 10),
									time: time.substring(11, 16),
									AM: that.setAm(time.substring(17, 19)),
									url: item.hasfeatureimageurl,
									temperature: item.temperature
								})
							})
							this.records = records
						} else {
							uni.showModal({
								content: res.data.message,
								showCancel: false,
								cancelText: this.$t('sure'),
								confirmText: this.$t('cancel')
							})
						}
					}
				});
			},
			setAm(am){
				let text = ''
				switch(am){
					case '早上':
					case '上午':
					text = this.$t('moring')
					break
					case '中午':
					text = this.$t('noon')
					break
					case '下午':
					text = this.$t('afternoon')
					break
					default:
					text = this.$t('night')
					break
				}
				return text
			}
		}
	}

</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>
